﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AutoUpgrade
{
    /// <summary>
    /// 进度组件
    /// </summary>
    internal class ProgressControl : Control
    {

        private float m_value { get; set; } = 0;

        public ProgressControl()
        {
            // 在 InitializeComponent() 调用之后添加任何初始化。
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            base.SetStyle(ControlStyles.UserPaint, true);
        }

        public float Value
        {
            get => this.m_value;
            set
            {
                if (value > 1)
                    value = 1;
                else if (value < 0 || value == default)
                    value = 0;
                if (m_value != value)
                {
                    this.m_value = value;
                    this.Invalidate();
                }
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {

            Rectangle rect = new Rectangle(0, 0, (int)(this.Width * this.Value), this.Height);
            using (SolidBrush Brush = new SolidBrush(Color.FromArgb(231, 231, 231)))
            {
                e.Graphics.FillRectangle(Brush, new Rectangle(0, 0, this.Width, this.Height));
                Brush.Color = Color.FromArgb(0, 145, 229);
                e.Graphics.FillRectangle(Brush, rect);
            }
        }
    }
}
